<template>
  <view class="phxx-item-detail" style="padding-bottom: 0rpx">
    <view class="content-box">
      <view class="bottom block-back">
        <view class="title-box"
          >基本信息<label class="edit-btn" @click="editFun(itemList.id)"
            >编辑</label
          ></view
        >
        <view class="line"></view>
        <view class="items">
          <text class="til col99">供应商名称</text>
          <text class="val col33">{{ itemList.cusName || '-' }}</text>
        </view>
        <view class="items">
          <text class="til col99">联系电话</text>
          <text class="val col33">{{ itemList.cusPhone || '-' }}</text>
        </view>
        <view class="items">
          <text class="til col99">企业类别</text>
          <text class="val col33">{{ cusTypeName || '-' }}</text>
        </view>
        <view class="items">
          <text class="til col99">结算类型</text>
          <text class="val col33">{{ settleName || '-' }}</text>
        </view>
        <view class="items">
          <text class="til col99">地址</text>
          <text class="val col33 adressBox">{{ itemList.address || '-' }}</text>
        </view>
      </view>
      <view class="bottom block-back">
        <view class="title-box">产品信息</view>
        <view class="line"></view>

        <view
          class="items-pro"
          v-for="items in itemList.productListBasicVOS"
          @click.stop="handleDetail(items.id)"
        >
          <view class="til col99 width350">{{ items.proName }}</view>
          <view class="val col33"
            >{{ items.proPrice + '元/吨' || '-'
            }}<uni-icons type="forward" size="20" v-if="!isDisabled"></uni-icons
          ></view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getDetails } from '@/api/supplier.js';
import { getDictList } from '@/api/login';
export default {
  data() {
    return {
      rowId: '',
      isMore: 'more',
      coalTypeList: [],
      productList: [],
      queryParam: {
        pageNo: 1,
        pageSize: 5
      },
      itemList: {
        id: undefined,
        cusName: undefined,
        cusPhone: undefined,
        cusProvince: undefined,
        cusCity: undefined,
        cusCounty: undefined,
        cusTown: undefined,
        regAddress: undefined,
        address: undefined,
        contactPerson: undefined,
        productManagementBaseVOS: []
      },
      companyRange: [],
      cusTypeName: '',
      settleName: ''
    };
  },
  onLoad(options) {
    if (!!options) {
      if (!!options.id) {
        this.getDetail(options.id);
      }
    }
  },
  methods: {
    handleDetail(id) {
      uni.navigateTo({
        url: `/packageB/pages/common/product-details/index?id=${id}`
      });
    },
    async getDetail(id) {
      let _ = this;
      let data = await getDetails(id);
      if (data.code == 0) {
        _.itemList.id = data.data.id;
        _.itemList.cusName = data.data.cusName;
        _.itemList.cusPhone = data.data.cusPhone;
        _.itemList.cusType = data.data.cusType;
        _.itemList.address = data.data.address;
        this.getDictLists(data.data.cusType);
        if (data.data.settlementNodeCode == 1) {
          _.settleName = '出矿过重';
        } else if (data.data.settlementNodeCode == 2) {
          _.settleName = '入厂过重';
        }

        _.itemList.productListBasicVOS = data.data.productListBasicVOS || [];
      }
    },
    editFun(id) {
      uni.redirectTo({
        url: `/packageB/pages/common/supplier-editing/index?id=${id}`
      });
    },
    async getDictLists(type) {
      const res = await getDictList();
      if (res.code === 0) {
        this.companyRange = (res?.data || []).filter(
          (e) => e.dictType === 'enter_type'
        );
        this.companyRange.forEach((item) => {
          if (Number(item.value) == type) {
            this.cusTypeName = item.label;
          }
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.phxx-list {
  padding: 20rpx;

  .item + .item {
    margin-top: 20px;
  }
}
.adressBox {
  white-space: normal;
  word-break: break-all;
  line-height: 40rpx;
  position: relative;
  top: 19rpx;
}
</style>
